home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
MM3Tp.sea Folder
/
Made by Marksman
/
Sources
/
mm
/
mmD_My_Modal.p
< prev
next >
Wrap
Text File
|
1994-01-16
|
10KB
|
306 lines
Unit mmD_My_Modal;
{ mmD_My_Modal Handle this dialog }
{ Copyright © 1994 George R. Cossey }
{ File name: mmD_My_Modal
Function: Handle this modal dialog.
This dialog is called when:
History: 1/16/94 Original by George Cossey
}
interface
uses
Printing,Folders,Sound,mmCommonMM_Demo,CommonMM_Demo, {}
mmPA_My_Alert,
UMy_Modal;
procedure InitD_My_Modal;
procedure MPD_My_Modal;
{ ======================================================= }
{ ======================================================= }
implementation
{ ======================================================= }
{ ======================================================= }
{ Routine: InitD_My_Modal }
{ Purpose: Initialize the modal dialog, globals and call users routine }
procedure InitD_My_Modal;
begin
Rec_My_Modal.theDialog := nil;
Rec_My_Modal.Enable_Cancel2 := true; { Button }
Rec_My_Modal.Enable_OK3 := true; { Button }
Rec_My_Modal.Enable_Checkboxes := true; { Checkbox }
Rec_My_Modal.Value_Checkboxes := 1;
Rec_My_Modal.Enable_for_selections := true; { Radio }
Rec_My_Modal.Value_for_selections := 0;
Rec_My_Modal.Enable_Radio_buttons := true; { Radio }
Rec_My_Modal.Value_Radio_buttons := 1;
Rec_My_Modal.Enable_PopUp := true; { Popup menu }
Rec_My_Modal.Value_PopUp := 1;
D_Init_My_Modal;
end;
{ ======================================================= }
{ Routine: MyFilter }
{ Purpose: Filter routine for dialog events }
function MyFilter(theDialog:DialogPtr;var theEvent:EventRecord;var itemHit:integer):Boolean;
var
MyPt:Point; { Current list selection point }
tempRect:Rect; { Temporary rectangle }
DType:integer; { Type of dialog item }
DItem:Handle; { Handle to the dialog item }
CItem:ControlHandle; { Control handle }
chCode:integer; { Key entered }
code:integer; { Used for FindControl }
LTemp:longint; { Used for time delay }
MyCmdKey:char; { The command key }
CmdDown:Boolean; { Flag for command key used }
valMyFilter:Boolean; { Value to return }
begin
{ Call the user routine }
valMyFilter := D_Filter_My_Modal(theDialog,theEvent,itemHit);
{ Only do on an update }
if ((theEvent.what = updateEvt) and (WindowPtr(theEvent.message) = theDialog)) then
begin
BeginUpdate(theDialog); { Start the update }
DrawDialog(theDialog); { Draw the controls }
valMyFilter := TRUE; { Pass out this special itemHit number }
itemHit := 32000; { Our special ID }
end;
if (theEvent.what = mouseDown) then { Only do on a mouse click }
begin
MyPt := theEvent.where; { Get the point where the mouse was clicked }
GlobalToLocal(MyPt); { Convert global to local }
end;
CheckKeysInDialog(theDialog,valMyFilter,theEvent,itemHit);
MyFilter := valMyFilter;
end;
{ ======================================================= }
{ Routine: Refresh_Dialog }
{ Purpose: Refresh the dialogs non-controls }
procedure Refresh_Dialog;
var
rTempRect:Rect; { Temp rectangle used for drawing }
DType:integer; { Type of dialog item }
DItem:Handle; { Handle to the dialog item }
CItem:ControlHandle; { Control handle }
Saved_ForeColor:RGBColor; { Save colors }
Saved_BackColor:RGBColor; { Save colors }
DrawingColor:RGBColor; { Place to make colors }
begin
SetPort(Rec_My_Modal.theDialog); { Point to our dialog window }
rTempRect := tempRect; { Save the current contents of tempRect }
if (Has.ColorQD) then { See if color QuickDraw is around }
begin
GetForeColor(Saved_ForeColor); { Save the fore color }
GetBackColor(Saved_BackColor); { Save the back color }
RGBForeColor(Black_ForeColor); { Set the fore color to Black }
RGBBackColor(White_BackColor); { Set the back color to White }
end;
{ This is the default selection, when RETURN is pressed. }
HiliteDefaultButton(Rec_My_Modal.theDialog,ResD_Cancel2);
{ Draw static text }
DrawStaticLine(sResD_Static_Text6,160,95,12,systemFont,[underline]);
{ Draw static text }
DrawStaticLine(sResD_Static_Text5,10,30,12,helvetica,[bold]);
{ Draw static text }
DrawStaticLine(sResD_Static_Text4,20,10,12,systemFont,[]);
TextSize(12);
TextFont(systemFont); { Select the Font that we want }
TextFace([]); { Select the style that we want }
if (Has.ColorQD) then { See if color QuickDraw is around }
begin
RGBForeColor(Saved_ForeColor); { Restore the fore color }
RGBBackColor(Saved_BackColor); { Restore the back color }
end;
D_Refresh_My_Modal(Rec_My_Modal.theDialog); { Call user refresh routine }
end;
{ ======================================================= }
{ Routine: MPD_My_Modal }
{ Purpose: Modal dialog }
procedure MPD_My_Modal;
var
tempRect:Rect; { Temporary rectangle }
DType:integer; { Type of dialog item }
Index:integer; { For looping }
DItem:Handle; { Handle to the dialog item }
CItem:ControlHandle; { Control handle }
CTempItem:ControlHandle; { Control handle }
sTemp:Str255; { Get text entered, temp holding }
itemHit:integer; { Get selection }
temp:integer; { Get selection, temp holding }
theSelection:integer; { For Palettes }
theLong,LTemp2:longint; { For Hotspot setup }
theRow:integer; { This is used to define the row used in a list }
ThisFontInfo:FontInfo; { Used to determine List element height }
ThisEditText:TEHandle; { Handle to get the Dialogs TE record }
TheDialogPtr:DialogPeek; { Pointer to Dialogs definition record, contains the TE record }
SavedPort:GrafPtr; { Previous grafport }
ExitDialog:Boolean; { Flag used to exit the Dialog }
MyPt:Point;
begin
GetPort(SavedPort); { Get the previous grafport }
HoldOffUserEvents := true; { Hold off the user events }
Rec_My_Modal.theDialog := GetNewDialog(ResD_My_Modal,nil,WindowPtr(-1));{ Bring in the dialog resource }
SetPort(Rec_My_Modal.theDialog); { Prepare to add conditional text }
TheDialogPtr := DialogPeek(Rec_My_Modal.theDialog); { Get to the inner record }
ThisEditText := TheDialogPtr^.textH; { Get to the TE record }
HLock(Handle(ThisEditText)); { Lock it for safety }
ThisEditText^^.txSize := 12; { TE Point size }
TextSize(12); { Window Point size }
ThisEditText^^.txFont := systemFont; { TE Font ID }
TextFont(systemFont); { Window Font ID }
ThisEditText^^.txFont := 0; { TE Font ID }
ThisEditText^^.fontAscent := 12; { Font ascent }
ThisEditText^^.lineHeight := 12 + 3 + 1; { Font ascent + descent + leading }
HUnlock(Handle(ThisEditText)); { UnLock the handle when done }
tempRect := Rec_My_Modal.theDialog^.portRect; { Get the windows position and size }
tempRect.left := ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) div 2; { Center Horz }
tempRect.top := ((screenBits.bounds.bottom - screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) div 3; { 1/3 vert }
if (tempRect.top < 40) then { Keep below the menu bar }
tempRect.top := 40;
MoveWindow(Rec_My_Modal.theDialog,tempRect.left,tempRect.top,true);
{ Button }
SetupNormalControl(Rec_My_Modal.theDialog,ResD_Cancel2,Rec_My_Modal.Enable_Cancel2,0);
{ Button }
SetupNormalControl(Rec_My_Modal.theDialog,ResD_OK3,Rec_My_Modal.Enable_OK3,0);
{ Checkbox }
SetupNormalControl(Rec_My_Modal.theDialog,ResD_Checkboxes,Rec_My_Modal.Enable_Checkboxes,
Rec_My_Modal.Value_Checkboxes);
{ Radio button }
SetupNormalControl(Rec_My_Modal.theDialog,ResD_for_selections,Rec_My_Modal.Enable_for_selections,
Rec_My_Modal.Value_for_selections);
{ Radio button }
SetupNormalControl(Rec_My_Modal.theDialog,ResD_Radio_buttons,Rec_My_Modal.Enable_Radio_buttons,
Rec_My_Modal.Value_Radio_buttons);
SetupPopupMenu(Rec_My_Modal.theDialog,ResD_PopUp,Rec_My_Modal.Enable_PopUp,
mResD_PopUp,Rec_My_Modal.Value_PopUp);
ExitDialog := false; { Do not exit dialog handle loop yet }
D_Setup_My_Modal(Rec_My_Modal.theDialog); { Call user Dialog setup routine }
ShowWindow(Rec_My_Modal.theDialog); { Open a dialog box }
SelectWindow(Rec_My_Modal.theDialog); { Lets see it }
repeat { Start of dialog handle loop }
ModalDialog(@MyFilter,itemHit); { Wait until an item is hit }
D_Hit_My_Modal(Rec_My_Modal.theDialog,itemHit,ExitDialog);{ Let user handle the item hit }
if (itemHit = 32000) then { Check for update }
begin
Refresh_Dialog; { Draw any Lists, lines, or rectangles }
EndUpdate(Rec_My_Modal.theDialog); { End of the update }
end
else
begin
GetDItem(Rec_My_Modal.theDialog,itemHit,DType,DItem,tempRect); { Get item information }
CItem := ControlHandle(DItem); { Get the control handle }
end;
{ Handle it real time }
if (itemHit = ResD_Cancel2) then { Handle the Button being pressed }
begin
ExitDialog := true; { Close this dialog, exit }
end;
if (itemHit = ResD_OK3) then { Handle the Button being pressed }
begin
ExitDialog := true; { Close this dialog, exit }
end;
if (itemHit = ResD_Checkboxes) then { Handle the checkbox being pressed }
begin
temp := GetCtlValue(CItem); { Get the current Checkbox value }
SetCtlValue(CItem,BAND((temp + 1),1)); { Toggle the value to the opposite }
Rec_My_Modal.Value_Checkboxes := GetCtlValue(CItem); { Get the current Checkbox value }
end;
if (itemHit = ResD_for_selections) then { Handle the Radio being pressed }
begin
SetCtlValue(CItem,1);
Rec_My_Modal.Value_for_selections := 1; { Set the current Radio value }
ClearTheRadio(Rec_My_Modal.theDialog,ResD_Radio_buttons,Rec_My_Modal.Value_Radio_buttons);
end;
if (itemHit = ResD_Radio_buttons) then { Handle the Radio being pressed }
begin
SetCtlValue(CItem,1);
Rec_My_Modal.Value_Radio_buttons := 1; { Set the current Radio value }
ClearTheRadio(Rec_My_Modal.theDialog,ResD_for_selections,Rec_My_Modal.Value_for_selections);
end;
{Popup}
until (ExitDialog); { Handle dialog items until exit selected }
{ Get results after dialog }
D_Exit_My_Modal(Rec_My_Modal.theDialog); { Exiting the modal dialog }
SetPort(SavedPort); { Restore the previous grafport }
DisposDialog(Rec_My_Modal.theDialog); { Flush the dialog out of memory }
HoldOffUserEvents := false; { Let in the user events }
end;
{ ======================================================= }
{ ======================================================= }
end.